package net.hzlj.platform.enterprise.helper;

import android.app.Service;
import android.os.Vibrator;
import android.util.Log;

import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

import net.hzlj.platform.enterprise.BootApp;
import net.hzlj.platform.enterprise.common.Constant;
import net.hzlj.platform.enterprise.utils.AppPreferencesUtils;
import net.hzlj.platform.enterprise.utils.PreferencesUtils;


/**
 * @Description:
 * @Author: Jason Zhang
 * @Date: 2016/12/5 0005
 */

public class BaiduLBSManager {

    private static final String TAG = BaiduLBSManager.class.getSimpleName();

    private static BaiduLBSManager instance = new BaiduLBSManager();

    // Baidu LBS
    public LocationClient locationClient;
    public Vibrator vibrator;

    public static BaiduLBSManager getInstance(){
        return instance;
    }

    private BaiduLBSManager(){
        locationClient = new LocationClient(BootApp.getAppContext());
        vibrator = (Vibrator) BootApp.getAppContext().getSystemService(
                Service.VIBRATOR_SERVICE);
    }

    public void refreshLocationTime(BDLocationListener listener){
        locationClient.registerLocationListener(listener);
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType("bd09ll");// 返回的定位结果是百度经纬度,默认值gcj02
        //SharedPreferencesUtil.getLocationInterval() *
        int locationInterval = AppPreferencesUtils.getInt(BootApp.getAppContext(),PreferencesUtils.KEY_LOCATION_INTERVAL, Constant.Socket.DEFAULT_LOCATION_TIME);
        Log.i(TAG,"locationInterval:" + locationInterval);
        option.setScanSpan(locationInterval * 1000);// 设置发起定位请求的间隔时间为5000ms
        option.setIsNeedAddress(true);
        option.setNeedDeviceDirect(true);// 返回的定位结果包含手机机头的方向
        locationClient.setLocOption(option);
    }

    public LocationClient getLocationClient(){
        return locationClient;
    }

}
